﻿@{
    ViewBag.Title = "视频查询";
    Layout = "~/Views/Shared/_JQBaseLayOut.cshtml";
    string videoSavePath = WoChu.Infrastructure.Web.ConfigSetting.GetConfigValueByName<string>("Video.WebUrl");
    int backMin = WoChu.Infrastructure.Web.ConfigSetting.GetConfigValueByName<int>("Video.CheckBackMin");
}

@section JQscriptSection{
    <script type="text/javascript">
        var _videoWebUrl = "@videoSavePath";
        var _backMin="@backMin";
        $(document).ready(function () {
            Init();
        });

        //初始化数据
        function Init() {
            
            var orderNo = $.getQueryString("orderno");            
           
            $("#dg").datagrid({
                url: "/Report/GetCheckVideoList",
                queryParams: {
                    SHEETID: orderNo, TYPE: 1, SUBTYPE: $.getQueryString("subtype"),
                    CheckLocation: $.getQueryString("checklocation"), EndDate: $.getQueryString("checkdate")
                },
                columns: [[
               { field: 'DURATION', title: '视频审核前长度(秒)+审核后' + _backMin+"分", width: 100 },
               {
                   field: 'State', title: '操作', width: 100,
                   formatter: function (value, row, rowIndex) {
                      // $('#dg').datagrid('selectRow', index);// 关键在这里  
                       var btn = "";
                       var text = getButtonText(value);
                       if (value==2 )
                       {
                           btn = "<button type='button' onclick='videoDownload(" + rowIndex + ")'>" + text + "</button>";
                           //btn = "<a href='javascript:void(0)' ='videoPlay(" + rowIndex + ")'>" + text + "</button>";
                       }
                       else if(value==0)
                           btn = "<button type='button' onclick='videoCreate(" + rowIndex + ",this)'>" + text + "</button>";
                       else
                           btn = "<button type='button' disabled='disabled'>" + text + "</button>";
                       return btn;
                   }
               },
              // {field:'price',title:'Price',width:100,align:'right'}   
                ]],
                idField: "ID",
                method: 'get',
                fit: true,
                pagination: false,    
                fitColumns: true,
                singleSelect: true
            });
          
        }

        function videoCreate(rowIndex, btn) {
            var row = selectRow(rowIndex);
            if (!row) return;

            HandleTips.openLoading();
            var url = "/Report/CreateVideo";
            var checkDate = $.getQueryString("checkdate");

            var data = {
                SHEETID: $.getQueryString("orderno"), TYPE: 1, SUBTYPE: $.getQueryString("subtype"), DURATION: row.DURATION,
                CheckLocation: $.getQueryString("checklocation"), EndDate: checkDate
            };
            var $btn = $(btn);
            $btn.text("处理中");
            $.ajaxPost(url, data, function (response) {
                //$.messager.progress('close');
                HandleTips.closeLoading();
                if (response.IsSuccess) {
                    $btn.text(getButtonText(2));
                    var onclick = $btn.attr("onclick").replace("videoCreate", "videoDownload");
                    row["FILENAME"] = response.UserData;
                    $btn.attr("onclick", onclick);
                }
                else {
                    $btn.text(getButtonText(0));
                    if (response.UserData == 1)
                        $('#dg').datagrid('reload');    // reload the current page data  

                }
                HandleTips.Alert(response.Message);
            });
        }

        function videoDownload(rowIndex)
        {            
            var row = selectRow(rowIndex);
            if (!row) return;

            var videoFile = _videoWebUrl + row.FILENAME;
            $("#iframe").attr("src", videoFile);
            // document.frames("iframe").document.execCommand("SaveAs");
        }

        

        function videoPlay(rowIndex)
        {
            var row = selectRow(rowIndex);
            if (!row) return;

            var videoFile = _videoWebUrl + row.FILENAME;
            //var fso; // filespec="C:/path/myfile.txt"
            //fso=new ActiveXObject("Scripting.FileSystemObject");
            //if (!fso.FileExists(videoFile))
            //{
            //    alert("视频文件不存在，是否重新生成");
            //}
            $.log(videoFile);
            $("#videoContain").attr("src", videoFile);
          //  $("#videoContain").attr("width", 800);
            $("#videoContain").attr("height", 770);
            $("#videoContain").focus();
            HandleTips.openLoading();
            $("#videoContain").bind('play', function () {
                HandleTips.closeLoading();
            });
        }

        function getButtonText(state)
        {
            var text = { 0: "生成", 1: "下载中", 2: "下载" };       //和后台枚举类似  VideoState     
            return text[state];
        }

        function selectRow(rowIndex)
        {
            $('#dg').datagrid('selectRow', rowIndex);// 关键在这里  
            var row = $("#dg").datagrid('getSelected');
            return row;
        }

        function test()
        {
            //var videoFile = "/VideoUntity/video/C12_20160718052050_20160718052450.mp4";
            var videoFile = "/video/d.mp4";
            $("#iframe").attr("src", videoFile);
            //$("#iframe")[0].document.execCommand("SaveAs");
        }
    </script>

    <style type="text/css">
      
        /*audio:-webkit-full-page-media, video:-webkit-full-page-media {
                max-height: 100%;
                max-width: 100%;
            }
        user agent stylesheet
        video:-webkit-full-page-media {
            position: absolute;
            top: 0px;
            right: 0px;
            bottom: 0px;
            left: 0px;
            margin: auto;
        }
        user agent stylesheet
        video {
            object-fit: contain;
        }*/
    </style>
}
<body style="background-color: ButtonFace; font-size: 17px">   
    <iframe id="iframe" name="iframe" style=" height:0; width:0; display:none;" ></iframe>
   @* <a href="javascript:test();">下载1</a>*@    
    <div style="width:100%;height:250px">
        <table id="dg" style="width:400px;height:250px"></table>
        @*<video id="videoContain" autoplay="autoplay"
               controls="controls" style="display:block;">
            您的浏览器不支持此种视频格式。
        </video>*@
    </div>
   
     
    @*<script src="@Url.Content("~/Scripts/common/xdate.js")" type="text/javascript"></script>*@
</body>


